package com.example.javaproject.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.javaproject.entity.Position;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Map;

@Mapper
public interface PositionMapper extends BaseMapper<Position> {
    List<Map<String, Object>> selectApplicationStats();
    Map<String, Object> selectPositionWithTeacher(Integer id);
    List<Map<String, Object>> selectAllPositionsWithTeacher();

    // 教师岗位分页查询
    default Map<String, Object> selectTeacherPositions(Map<String, Object> params) {
        Integer teacherId = (Integer) params.get("teacherId");
        String name = (String) params.get("name");
        String location = (String) params.get("location");
        Integer status = (Integer) params.get("status");
        Integer page = (Integer) params.get("page");
        Integer size = (Integer) params.get("size");
        int offset = (page - 1) * size;
        // 查询数据列表
        List<Map<String, Object>> records = selectTeacherPositionsList(teacherId, name, location, status, offset, size);
        // 查询总数
        Integer total = selectTeacherPositionsCount(teacherId, name, location, status);
        Map<String, Object> result = new java.util.HashMap<>();
        result.put("records", records);
        result.put("total", total);
        result.put("current", page);
        result.put("size", size);
        return result;
    }

    List<Map<String, Object>> selectTeacherPositionsList(
        Integer teacherId, String name, String location, Integer status, Integer offset, Integer size
    );
    Integer selectTeacherPositionsCount(
        Integer teacherId, String name, String location, Integer status
    );
}